import { createRouter, createWebHistory } from 'vue-router'
const Login = ()=>import('../view/Longin')
const Home = ()=>import('../view/Home')
const Users = ()=>import('../components/user/Users')
const Rights = ()=>import('../components/power/rights/Rights')
const Roles = ()=>import('../components/power/roles/Roles')
const Cate = ()=>import('../components/goods/categories/Cate')
const  Params = ()=>import('../components/goods/params/params')
const Goods = ()=>import('../components/goods/goods/goods')
const Orders = ()=>import('../components/orders/orders')
const Reports = ()=>import('../components/reports/reports')
const routes = [
  {
    path:'',
    redirect:'/login'
  },
  {
    path:'/login',
    name:'Login',
    component:Login
  },
  {
    path:'/home',
    name:'首页',
    redirect: '/home/users',
    component:Home,
    children:[
      {
        path:'users',
        name:'用户管理界面',
        component:Users
      },
      {
        path:'rights',
        name:"权限列表",
        component:Rights
      },
      {
        path:'roles',
        name:'角色列表',
        component:Roles
      },
      {
        path:'categories',
        name:'商品分类',
        component:Cate
      },
      {
        path:'params',
        name:'商品参数',
        component:Params
      },
      {
        path:'goods',
        name:'商品列表',
        component:Goods
      },
      {
        path:'orders',
        name:'订单列表',
        component:Orders
      },
      {
        path:'reports',
        name:'数据报表',
        component:Reports
      }
    ]
  }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})
router.beforeEach((to,from,next)=>{
  document.title = to.name;
  if(to.path === '/login') return next()
  const tokenStr = window.sessionStorage.getItem('token')
  // if(!tokenStr) return next('/login')
  next();
})

export default router
